package cn.wolfcode.car.business.web.controller;


import cn.wolfcode.car.business.domain.BusCustomer;
import cn.wolfcode.car.business.query.BusCustomerQuery;
import cn.wolfcode.car.business.service.IBusCustomerService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/busCustomer")
public class BusCustomerController {
    //模板前缀
    private static final String prefix = "/business/busCustomer/";

    @Autowired
    private IBusCustomerService busCustomerService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:busCustomer:view")
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    @RequiresPermissions("business:busCustomer:add")
    @RequestMapping("/addPage")
    public String addPage(){
        return prefix + "add";
    }


    @RequiresPermissions("business:busCustomer:edit")
    @RequestMapping("/editPage")
    public String editPage(Long id, Model model){
        model.addAttribute("busCustomer", busCustomerService.get(id));
        return prefix + "edit";
    }

    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:busCustomer:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<BusCustomer> query(BusCustomerQuery qo){
        return busCustomerService.query(qo);
    }

    //新增
    @RequiresPermissions("business:busCustomer:add")
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusCustomer busCustomer){
        busCustomerService.save(busCustomer);
        return AjaxResult.success();
    }

    //编辑
    @RequiresPermissions("business:busCustomer:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(BusCustomer busCustomer){
        busCustomerService.update(busCustomer);
        return AjaxResult.success();
    }
 /*   //删除
    @RequiresPermissions("business:busCustomer:remove")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        busCustomerService.deleteBatch(ids);
        return AjaxResult.success();
    }*/
    //软删除
    @RequiresPermissions("system:busServiceItem:remove")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult updateDeleteBatch(Long id){
        busCustomerService.updateDeleteBatch(id);
        return AjaxResult.success();
    }
    //文件导出
    @RequestMapping("/exportExcel")
    @ResponseBody
    public void exportExcel(HttpServletResponse response) throws IOException {
        response.setHeader("Content-Disposition","attachment;filename=details.xlsx");
        Workbook workbook = busCustomerService.exportExcel();
        workbook.write(response.getOutputStream());
    }
}
